<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
class Goodsattrdetailscontroller extends Controller
{
    //
    public function add()
    {
    	$title = '商品属性详情页';
    	//查询所有的商品属性
    	$data = DB::table('goodsattr')->distinct()->lists('name');
    	// var_dump($data);
    	// die();
    	return view('admin.goodsattrdetails.add',['title'=>$title,'data'=>$data]);
    }

    //insert
    public function insert(Request $request)
    {
    	$data = $request -> except('_token');
    	// var_dump($data);
    	// die();
    	$res = DB::table('goodsattrdetails')-> insert($data);
    	if($res)
		{
			return redirect('/admin/goodsattrdetails/index') -> with('success','添加成功');
		}else
		{
			return back() -> with('error','添加失败');
		}
    }

    //index
    public function index()
    {
    	$title = '商品属性详情列表页';
    	$data = DB::table('goodsattrdetails')->get();
    	// var_dump($data);
    	// die();
    	return view('admin.goodsattrdetails.index',['title'=>$title,'data'=>$data]);
    }

    //edit
    public function edit($id)
    {
    	// var_dump($id);
    	// die();
    	$data = DB::table('goodsattrdetails') -> where('id','=',$id) -> first();
    	// var_dump($data);
    	// die();
    	$title = '商品属性详情修改页';
    	return view('admin.goodsattrdetails.edit',['title'=>$title,'data'=>$data]);
    }

    //
    public function update(Request $request)
    {
    	$data = $request -> except('_token');
    	// var_dump($data);
    	// die();
    	$res = DB::table('goodsattrdetails')->where('id','=',$data['id'])->update($data);
    	if($res)
		{
			return redirect('/admin/goodsattrdetails/index') -> with('success','修改成功');
		}else
		{
			return back() -> with('error','修改失败');
		}
    }
    public function delete($id)
    {
    	$res = DB::table('goodsattrdetails')-> where('id','=',$id) ->delete();
   
    if($res)
		{
			return redirect('/admin/goodsattrdetails/index') -> with('success','删除成功');
		}else
		{
			return back() -> with('error','删除失败');
		}
    }		
} 
